package leecode

func minimumLevels(possible []int) int {
	for i := 0; i < len(possible); i++ {
		if possible[i] == 0 {
			possible[i] = -1
		}
	}
	prefix := make([]int, len(possible)+1)
	for i := 0; i < len(possible); i++ {
		prefix[i+1] = prefix[i] + possible[i]
	}
	for i := 1; i < len(prefix); i++ {
		if i < len(possible) && prefix[i] > prefix[len(prefix)-1]-prefix[i] {
			return i
		}
	}
	return -1
}
